package palmtop.com.palmtop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;

import java.lang.reflect.Type;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import palmtop.com.palmtop.R;
import palmtop.com.palmtop.adapter.ReportpopulationAdapter;
import palmtop.com.palmtop.adapter.TaskAdapter;
import palmtop.com.palmtop.model.Reportpopulation;
import palmtop.com.palmtop.model.Task;
import palmtop.com.palmtop.util.Config;
import palmtop.com.palmtop.util.NetUtil;

public class PopulationacountActivity extends BaseActivity {

    @BindView(R.id.mtitle)
    TextView mtitle;
    @BindView(R.id.populationList)
    ListView populationList;

    private ArrayList<Reportpopulation> arrlist;
    private ReportpopulationAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_population, Config.toptitle, 1);
        MyApplication app = (MyApplication) getApplication();
        app.addActivityList(PopulationacountActivity.this);
        ButterKnife.bind(this);
        initView();

    }

    private void initView() {
        arrlist = new ArrayList<Reportpopulation>();
        mtitle.setText("基础信息上报");
        /*Reportpopulation t1 = new Reportpopulation();
        Reportpopulation t2 = new Reportpopulation();
        t1.setUnitname("西关派出所");
        t2.setUnitname("东关派出所");
        arrlist.add(t1);
        arrlist.add(t2);*/
        RequestParams params = new RequestParams(Config.SERVER_URL + "reportpopulation/unitcount");
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                Type listType = new TypeToken<ArrayList<Reportpopulation>>() {
                }.getType();
                final ArrayList<Reportpopulation> list = gson.fromJson(result,listType);
                adapter = new ReportpopulationAdapter(list,PopulationacountActivity.this);
                populationList.setAdapter(adapter);

                /*populationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent intent = new Intent();
                        intent.putExtra("reportpopulation",list.get(i));
                        intent.setClass(PopulationacountActivity.this,PopulationActivity.class);
                        startActivity(intent);
                    }
                });*/
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {}
            @Override
            public void onCancelled(CancelledException cex) {}
            @Override
            public void onFinished() {}
        });

    }
}
